<?php

// +----------------------------------------------------------------------
// | 后台主页控制器
// +----------------------------------------------------------------------

namespace app\controller\admin;

use app\event\sport\Chat;
use app\model\admin\Module as ModuleModel;
use think\helper\Str;
use yicmf\builder\Table;

class Task extends Common
{


    public function notice()
    {
        $modules = ModuleModel::where('status', 1)->where('is_install', 1)->select();

        $data = [];
        $count = 0;
        foreach ($modules as $module) {
            $this->app->getRootPath();
            $file = $this->app->getRootPath() .
                'app' . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR
                . $module['name']
                . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . Str::studly('home') . '.php';
            if (is_file($file)) {
                $name = '\app\controller\\' . $module['name'] . '\\admin\\' . Str::studly('home');
                $controller = new $name;
                foreach ($controller->wait() as $index => $item) {
                    if ($item['number'] > 0) {
                        $count = $count + $item['number'];
                    }
                }
            }

        }



        $data['data']['notice'] = $count;
        $data['message'] = '新任务';
        $data['code'] = 0;
        return json($data);

    }

    public function deal()
    {

        $modules = ModuleModel::where('status', 1)->where('is_install', 1)->select();

        $data = [];
        foreach ($modules as $module) {
            $this->app->getRootPath();
            $file = $this->app->getRootPath() .
                'app' . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR
                . $module['name']
                . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . Str::studly('home') . '.php';
            if (is_file($file)) {
                $name = '\app\controller\\' . $module['name'] . '\\admin\\' . Str::studly('home');
                $controller = new $name;
                foreach ($controller->wait() as $index => $item) {
                    if ($item['number'] > 0) {
                        $data[] = [
                            'id' => $index,
                            'title' => $item['title'],
                            'num' => $item['number'],
                            'create_time' => time_format(),
                            'action' => $item['link'],

                        ];
                    }
                }
            }

        }
        // 读取规则列表

        // 显示页面
        $builder = new Table();
        $builder
            ->keyId()
            ->keyText('num', '任务数量')
            ->keyTab('title', '执行', '{{d.action}}')
//				->keyBool('is_api','是否提交第三方')
            ->keyTime('create_time', '消息时间')
            ->data($data);
        return $builder->fetch();
    }


}
